package git.soulbgm.mapreduce.combiner;

import git.soulbgm.mapreduce.utils.DriverUtil;
import org.apache.hadoop.fs.Path;
import org.apache.hadoop.io.IntWritable;
import org.apache.hadoop.io.Text;
import org.apache.hadoop.mapreduce.Job;

import java.io.IOException;

/**
 * @author SoulBGM
 * @date 2021/11/18 0:07
 */
public class WordCountDriver {

    public static void main(String[] args) throws IOException, ClassNotFoundException, InterruptedException {
        Job job = DriverUtil.createJob(
                WordCountDriver.class, WordCountMapper.class, WordCountReducer.class,
                Text.class, IntWritable.class, Text.class, IntWritable.class,
                new Path(args[0]), new Path(args[1]));

        // Combiner能够应用的前提是不影响最终的业务逻辑
        // 设置Combiner处理类
        //job.setCombinerClass(WordCountCombiner.class);

        // 设置Reduce任务数为0 则Combiner也就不会再运行
        //job.setNumReduceTasks(0);

        // 可以使用Reduce的类
        job.setCombinerClass(WordCountReducer.class);

        // 7 提交job
        boolean result = job.waitForCompletion(true);
        System.exit(result ? 0 : 1);
    }

}
